var websocket = null;
if("WebSocket" in window){
    websocket = new WebSocket("ws://localhost:8080/customWebSocket");
}else{
    alert("该浏览器不支持websocket");
}

websocket.onopen = function (evnet) {
    console.log("建立连接");
}

websocket.onclose = function (evnet) {
    console.log("连接关闭")
}

websocket.onmessage=function (evnet) {
    console.log("收到消息:"+evnet.data);
    layer.alert(evnet.data)
}

websocket.onerror = function () {
    alert("websocket通信发生错误 ！")
}
